package threads.lock;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchTest {
    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(1);
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    countDownLatch.await();
                    System.out.println(Thread.currentThread().getName()+ "：：： I have get the response of t3!");
                } catch (Exception ex) {
                    ex.printStackTrace();
                }

            }
        },"t1");
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    countDownLatch.await();
                    System.out.println(Thread.currentThread().getName()+"::: I have get the response of t3!");
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        },"t2");
        Thread t3 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.currentThread().sleep(3000);
                    System.out.println(Thread.currentThread().getName()+": I have done!");
                    countDownLatch.countDown();
                    System.out.println(Thread.currentThread().getName()+": I have done done!");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"t3");
        t1.start();
        t2.start();
        t3.start();
    }
}
